package com.oa.ylms.apps.dao.assess.impl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;


import com.oa.ylms.apps.constants.IDEDStates;
import com.oa.ylms.apps.dao.assess.IItemCategoryDao;
import com.oa.ylms.apps.entity.assess.ItemCategoryValue;

@SuppressWarnings("unchecked")
public class ItemCategoryDaoImpl extends HibernateDaoSupport implements
		IItemCategoryDao {

	public int addItemCategory(ItemCategoryValue itemCategory) throws Exception {
		if (itemCategory != null) {
			itemCategory.setStates(IDEDStates.ENABLE);
			this.getHibernateTemplate().save(itemCategory);
		}
		return itemCategory.getCategoryId();
	}

	public boolean editItemCategory(ItemCategoryValue itemCategory)
			throws Exception {
		if(itemCategory!=null)
		{
		try {
			this.getHibernateTemplate().update(itemCategory);
		} catch (Exception e) {
			return false;
		}
		return true;
		}
		return false;
	}

	public List<ItemCategoryValue> queryAllItemCategory() throws Exception {
		return this.getHibernateTemplate().find(
				"from ItemCategoryValue icv where icv.states=?",IDEDStates.ENABLE);
	}

	public ItemCategoryValue queryItemCategoryByCategoryId(int categoryId)
			throws Exception {
		return (ItemCategoryValue) this.getHibernateTemplate().get(
				ItemCategoryValue.class, categoryId);
	}

}
